package com.tuanzi.loan.web.bean.system;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.system.AdvertiseService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.system.AdvertiseSearchRequest;
import com.tuanzi.loan.vo.response.system.AdvertiseSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.system.AdvertiseLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.ADS_PLATFORM_TYPE;

/**
 * @author Ray 2017/09/21
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class AdvertiseListBean extends JSFListingSessionBean<AdvertiseSearchRequest, AdvertiseSearchResponse> {

	private static final long serialVersionUID = -2152778554108785342L;
	@Autowired
	private AdvertiseService advertiseService;

	public void onReset() {
		initLazyDataModel();
	}

	public String onAdd() {
		return redirect("/views/system/advertise/advertise-info.xhtml");
	}

	public String onEdit(String id) {
		return redirect("/views/system/advertise/advertise-info.xhtml?id=" + id);
	}

	public void onDelete(Long id){
		advertiseService.delete(id);
		addSuccessfullyMessage();
	}


	@Override
	protected String page() {
		return "/views/system/advertise/advertise-list.xhtml";
	}

	@Override
	protected void initLazyDataModel() {
		$ = new AdvertiseSearchRequest();
		lazyDataModel = new AdvertiseLazyDataModel($, session, advertiseService);
	}
	@Override
	protected List<String> getDictionaryCodes() {
		return Lists.newArrayList(ADS_PLATFORM_TYPE);
	}
}
